#ifndef PFS_SERVER_LOCATE_H
#define PFS_SERVER_LOCATE_H
#include <set>
#include <stdint.h>
#include <string>
#include "define.h"

using namespace std;

namespace PFS
{
    class ServerLocate
    {
        public:
            typedef set<uint32_t> BLOCK_SET;
        private:
            typedef set<uint32_t>::iterator BLOCK_SET_ITER;
        public:
            ServerLocate();
            virtual ~ServerLocate();
            inline void set_dead()
            {
                alive = false; 
            }
            inline bool is_alive() const
            {
                return alive; 
            }

            DataServerInfo* get_data_server();
            const DataServerInfo* get_data_server() const;
            const BLOCK_SET* get_block_list() const;
            const BLOCK_SET* get_writable_blocks() const;
            const BLOCK_SET* get_primary_writable_blocks() const;

            void add_block(const uint32_t block_id);
            void remove_block(const uint32_t block_id);
            void add_writable_block(const uint32_t block_id);
            void add_primary_writable_block(const uint32_t block_id);
            void remove_writable_block(const uint32_t block_id);
            void remove_primary_writable_block(const uint32_t block_id);


            void release(const uint32_t block_id);
            void clear();
    //        bool is_disk_full() const
            inline uint64_t elect(const uint64_t seq)
            {
                elect_seq = seq;
                return seq;
            }

            inline uint64_t get_elect_seq() const
            {
                return elect_seq;
            }
            
            uint32_t get_max_block_id() const;
        private:
            DataServerInfo ds_info;
            BLOCK_SET block_list;
            BLOCK_SET writeable_blocks;
            BLOCK_SET primary_blocks;
            bool alive;
            uint64_t elect_seq;
    };
}

#endif
